package com.freeter.modules.gjs.service.impl;

import com.freeter.modules.gjs.entity.TransferItems;
import com.freeter.modules.gjs.mapper.TransferItemsMapper;
import com.freeter.modules.gjs.service.TransferItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class TransferItemsServiceImpl implements TransferItemsService {
    
    @Autowired
    private TransferItemsMapper transferItemsMapper;
    
    @Override
    public List<TransferItems> getAllTransferItems() {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public TransferItems getTransferItemsById(Long id) {
        return transferItemsMapper.selectById(id);
    }
    
    @Override
    public List<TransferItems> getTransferItemsByTransferNo(String transferNo) {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public List<TransferItems> getTransferItemsByItemCode(String itemCode) {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public List<TransferItems> getTransferItemsByFromSiteCode(String fromSiteCode) {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public List<TransferItems> getTransferItemsByToSiteCode(String toSiteCode) {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public List<TransferItems> getTransferItemsByStatus(String status) {
        return transferItemsMapper.selectList(null);
    }
    
    @Override
    public TransferItems createTransferItems(TransferItems transferItems) {
        if (transferItems.getStatus() == null) {
            transferItems.setStatus("PENDING");
        }
        transferItems.setCreatedAt(LocalDateTime.now());
        transferItems.setUpdatedAt(LocalDateTime.now());
        transferItemsMapper.insert(transferItems);
        return transferItems;
    }
    
    @Override
    public TransferItems updateTransferItems(TransferItems transferItems) {
        transferItems.setUpdatedAt(LocalDateTime.now());
        transferItemsMapper.updateById(transferItems);
        return transferItems;
    }
    
    @Override
    public boolean deleteTransferItems(Long id) {
        return transferItemsMapper.deleteById(id) > 0;
    }
    
    @Override
    public boolean deleteTransferItemsByTransferNo(String transferNo) {
        return transferItemsMapper.delete(null) > 0;
    }
} 